package com.ruyuan.o2o.groupbuy.logcenter.es;

import org.apache.http.HttpHost;
import org.elasticsearch.client.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 搜索引擎es配置类
 *
 * @author mingqian
 */
@Configuration
public class ElasticsearchConfig {

    @Value("${customize.es.host}")
    public String esHost;

    @Value("${customize.es.port}")
    public Integer esPort;

    @Value("${customize.es.scheme}")
    public String scheme;

    @Bean
    public RestHighLevelClient esClient() {
        // 配置连接，多个ip逗号分隔
        RestClientBuilder builder = RestClient.builder(new HttpHost(esHost, esPort, scheme));
        // 超时时间配置, 可以根据实际业务需要可以反复多次测试，最终求得一个合理的参数
        builder.setRequestConfigCallback(requestConfigBuilder -> requestConfigBuilder.setSocketTimeout(10000));

        return new RestHighLevelClient(builder);
    }

}
